package com.dingreading.cloud.soms.util.wxtemplate;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 模板消息工具
 */
@RefreshScope
@Component
public class TemplateMessUtils {

    @Value("${wx.template.pushFunction}")
    private String pushFunction;

    public static TemplateMessUtils util;

    @PostConstruct
    public void init() {
        util = this;
    }

    /**
     * 剩余次数推送功能
     *
     * @param openid    服务号内的微信用户openid
     * @param memberName      用户姓名
     * @param leftLessonCntStr 剩余次数
     * @param beginTime      时间，yyyy-MM-dd hh:mm
     */
    public static String residueDegree(String openid, String productInfo, String beginTime, String memberName, String leftLessonCntStr) {
        String build = TemplateData.New()
                .setToUser(openid)
                .setTemplate_id(util.pushFunction)
                .setUrl("")
                .add("thing2", productInfo, "")
                .add("time8", beginTime, "")
                .add("thing17", memberName, "")
                .add("character_string29", leftLessonCntStr, "")
                .build();
        return build;
    }

}
